﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>积分商城 - 模切材料小管家</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root {
            /* TDesign 工业品色彩系统 */
            --primary-color: #0052d9;
            --primary-light: #266fe8;
            --primary-dark: #003cab;
            --secondary-color: #f2f3ff;
            --accent-color: #e37318;
            --success-color: #00a870;
            --warning-color: #ed7b2f;
            --error-color: #d54941;
            
            /* 背景色系 */
            --bg-color-page: #f5f7fa;
            --bg-color-container: #ffffff;
            --bg-color-secondray: #f8f9fc;
            
            /* 边框和分割线 */
            --border-color: #e7e7e7;
            --border-color-light: #f0f0f0;
            --border-radius-small: 3px;
            --border-radius-medium: 6px;
            --border-radius-large: 9px;
            
            /* 文字色彩 */
            --text-primary: #1a1a1a;
            --text-secondary: #4e5969;
            --text-placeholder: #86909c;
            --text-disabled: #c9cdd4;
            
            /* 阴影系统 */
            --shadow-1: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
            --shadow-2: 0 1px 4px 0 rgba(0, 0, 0, 0.08);
            --shadow-3: 0 4px 8px 0 rgba(0, 0, 0, 0.12);
            
            /* 间距系统 */
            --space-1: 4px;
            --space-2: 8px;
            --space-3: 12px;
            --space-4: 16px;
            --space-5: 20px;
            --space-6: 24px;
            --space-8: 32px;
            --space-10: 40px;
        }
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: "PingFang SC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
        }
        
        body {
            background-color: var(--bg-color-page);
            color: var(--text-primary);
            font-size: 14px;
            line-height: 1.5;
            padding-bottom: 64px;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }
        
        .container {
            max-width: 480px;
            margin: 0 auto;
            background: var(--bg-color-container);
            min-height: 100vh;
            box-shadow: var(--shadow-1);
            position: relative;
            overflow-x: hidden;
        }
        
        /* 头部样式 */
        .header {
            background: var(--primary-color);
            color: white;
            padding: var(--space-4);
            position: relative;
            z-index: 10;
        }
        
        .top-bar {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .back-btn {
            font-size: 18px;
            cursor: pointer;
            opacity: 0.9;
            transition: opacity 0.2s ease;
        }
        
        .back-btn:hover {
            opacity: 1;
        }
        
        .page-title {
            font-weight: 500;
            font-size: 16px;
        }
        
        .actions {
            display: flex;
            gap: var(--space-4);
        }
        
        .actions i {
            font-size: 16px;
            cursor: pointer;
            opacity: 0.9;
            transition: opacity 0.2s ease;
        }
        
        .actions i:hover {
            opacity: 1;
        }
        
        /* 用户积分显示 */
        .user-points {
            background: linear-gradient(135deg, var(--primary-color), #0066cc);
            color: white;
            padding: var(--space-4);
            margin: var(--space-4);
            border-radius: var(--border-radius-medium);
            text-align: center;
            box-shadow: var(--shadow-2);
        }
        
        .points-label {
            font-size: 14px;
            opacity: 0.9;
            margin-bottom: var(--space-1);
            color: white;
        }
        
        .points-value {
            font-size: 28px;
            font-weight: 700;
            margin-bottom: var(--space-2);
        }
        
        .points-note {
            font-size: 12px;
            opacity: 0.8;
        }
        
        /* 分类筛选按钮 */
        .filter-section {
            background: var(--bg-color-container);
            padding: var(--space-3) var(--space-4);
            margin-bottom: var(--space-2);
            border-bottom: 1px solid var(--border-color-light);
        }
        
        .filter-btn {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: var(--space-3);
            background: var(--bg-color-secondray);
            border: 1px solid var(--border-color-light);
            border-radius: var(--border-radius-medium);
            cursor: pointer;
            transition: all 0.2s ease;
        }
        
        .filter-btn:hover {
            background: var(--border-color-light);
        }
        
        .filter-btn-text {
            font-size: 14px;
            color: var(--text-primary);
        }
        
        .filter-btn-icon {
            color: var(--text-placeholder);
            font-size: 12px;
        }
        
        /* 模态框样式 */
        .modal-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.5);
            z-index: 1000;
            display: none;
            align-items: flex-end;
        }
        
        .modal-overlay.show {
            display: flex;
        }
        
        .modal-content {
            background: var(--bg-color-container);
            width: 100%;
            max-height: 60vh;
            border-radius: var(--border-radius-large) var(--border-radius-large) 0 0;
            padding: var(--space-6) var(--space-4) var(--space-4);
            transform: translateY(100%);
            transition: transform 0.3s ease;
        }
        
        .modal-overlay.show .modal-content {
            transform: translateY(0);
        }
        
        .modal-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: var(--space-4);
            padding-bottom: var(--space-3);
            border-bottom: 1px solid var(--border-color-light);
        }
        
        .modal-title {
            font-size: 16px;
            font-weight: 600;
            color: var(--text-primary);
        }
        
        .modal-close {
            font-size: 18px;
            color: var(--text-placeholder);
            cursor: pointer;
            padding: var(--space-1);
        }
        
        .category-options {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: var(--space-2);
        }
        
        .category-option {
            padding: var(--space-3);
            border: 1px solid var(--border-color-light);
            border-radius: var(--border-radius-medium);
            text-align: center;
            cursor: pointer;
            transition: all 0.2s ease;
            background: var(--bg-color-secondray);
            color: var(--text-secondary);
        }
        
        .category-option.active {
            background: var(--primary-color);
            color: white;
            border-color: var(--primary-color);
        }
        
        .category-option:hover {
            background: var(--primary-light);
            color: white;
        }
        
        /* 商品列表 */
        .products-section {
            padding: var(--space-4);
        }
        
        .products-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: var(--space-4);
        }
        
        .product-card {
            background: var(--bg-color-container);
            border-radius: var(--border-radius-medium);
            padding: var(--space-4);
            box-shadow: var(--shadow-1);
            border: 1px solid var(--border-color-light);
            cursor: pointer;
            transition: all 0.2s ease;
        }
        
        .product-card:hover {
            box-shadow: var(--shadow-3);
            transform: translateY(-2px);
        }
        
        .product-image {
            width: 100%;
            height: 100px;
            background: var(--bg-color-secondray);
            border-radius: var(--border-radius-medium);
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: var(--space-3);
            overflow: hidden;
        }
        
        .product-image i {
            font-size: 32px;
            color: var(--text-placeholder);
        }
        
        .product-image img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        
        .product-name {
            font-size: 14px;
            font-weight: 500;
            color: var(--text-primary);
            margin-bottom: var(--space-2);
            line-height: 1.4;
        }
        
        .product-points {
            font-size: 16px;
            font-weight: 700;
            color: var(--accent-color);
            margin-bottom: var(--space-2);
        }
        
        /* 收货信息模态框样式 */
        .address-modal-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.5);
            z-index: 1000;
            display: none;
            align-items: center;
            justify-content: center;
            padding: var(--space-4);
        }
        
        .address-modal-overlay.show {
            display: flex;
        }
        
        .address-modal-content {
            background: var(--bg-color-container);
            width: 100%;
            max-width: 400px;
            border-radius: var(--border-radius-large);
            padding: var(--space-6);
            box-shadow: var(--shadow-3);
            transform: scale(0.9);
            transition: transform 0.3s ease;
        }
        
        .address-modal-overlay.show .address-modal-content {
            transform: scale(1);
        }
        
        .address-modal-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: var(--space-5);
            padding-bottom: var(--space-3);
            border-bottom: 1px solid var(--border-color-light);
        }
        
        .address-modal-title {
            font-size: 18px;
            font-weight: 600;
            color: var(--text-primary);
        }
        
        .address-modal-close {
            font-size: 20px;
            color: var(--text-placeholder);
            cursor: pointer;
            padding: var(--space-1);
        }
        
        .address-form {
            display: flex;
            flex-direction: column;
            gap: var(--space-4);
        }
        
        .form-group {
            display: flex;
            flex-direction: column;
            gap: var(--space-2);
        }
        
        .form-label {
            font-size: 14px;
            font-weight: 500;
            color: var(--text-primary);
        }
        
        .form-input {
            padding: var(--space-3) var(--space-4);
            border: 1px solid var(--border-color);
            border-radius: var(--border-radius-medium);
            font-size: 14px;
            transition: all 0.2s ease;
            background: var(--bg-color-container);
        }
        
        .form-input:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 2px rgba(0, 82, 217, 0.1);
        }
        
        .form-textarea {
            padding: var(--space-3) var(--space-4);
            border: 1px solid var(--border-color);
            border-radius: var(--border-radius-medium);
            font-size: 14px;
            transition: all 0.2s ease;
            background: var(--bg-color-container);
            resize: vertical;
            min-height: 80px;
            line-height: 1.5;
        }
        
        .form-textarea:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 2px rgba(0, 82, 217, 0.1);
        }
        
        .address-form-actions {
            display: flex;
            gap: var(--space-3);
            margin-top: var(--space-4);
        }
        
        .btn-cancel {
            flex: 1;
            padding: var(--space-3) var(--space-4);
            border: 1px solid var(--border-color);
            border-radius: var(--border-radius-medium);
            background: var(--bg-color-secondray);
            color: var(--text-secondary);
            font-size: 14px;
            cursor: pointer;
            transition: all 0.2s ease;
        }
        
        .btn-cancel:hover {
            background: var(--border-color-light);
            color: var(--text-primary);
        }
        
        .btn-confirm {
            flex: 1;
            padding: var(--space-3) var(--space-4);
            border: none;
            border-radius: var(--border-radius-medium);
            background: var(--primary-color);
            color: white;
            font-size: 14px;
            cursor: pointer;
            transition: all 0.2s ease;
        }
        
        .btn-confirm:hover {
            background: var(--primary-dark);
        }
        
        .exchange-btn {
            width: 100%;
            padding: var(--space-2);
            border: none;
            border-radius: var(--border-radius-medium);
            background: var(--primary-color);
            color: white;
            font-size: 13px;
            cursor: pointer;
            transition: all 0.2s ease;
        }
        
        .exchange-btn:hover {
            background: var(--primary-dark);
        }
        
        .exchange-btn:disabled {
            background: var(--text-disabled);
            cursor: not-allowed;
        }
        
        /* 底部导航 */
        .tabbar {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            background: var(--bg-color-container);
            border-top: 1px solid var(--border-color);
            display: flex;
            z-index: 100;
            max-width: 480px;
            margin: 0 auto;
            height: 64px;
        }
        
        .tab-item {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding: var(--space-2) 0;
            cursor: pointer;
            transition: color 0.2s ease;
            color: var(--text-placeholder);
        }
        
        .tab-item.active {
            color: var(--primary-color);
        }
        
        .tab-item:hover {
            color: var(--primary-light);
        }
        
        .tab-item i {
            font-size: 18px;
            margin-bottom: var(--space-1);
        }
        
        .tab-item span {
            font-size: 10px;
        }
        
        /* 空状态 */
        .empty-state {
            text-align: center;
            padding: var(--space-10);
            color: var(--text-secondary);
        }
        
        .empty-state i {
            font-size: 48px;
            margin-bottom: var(--space-4);
            opacity: 0.5;
        }
        
        .empty-title {
            font-size: 16px;
            margin-bottom: var(--space-2);
        }
        
        .empty-desc {
            font-size: 14px;
            opacity: 0.8;
        }
    </style>
</head>
<body>
    <div class="container">
        <!-- 头部区域 -->
        <div class="header">
            <div class="top-bar">
                <div class="back-btn" onclick="history.back()">
                    <i class="fas fa-arrow-left"></i>
                </div>
                <div class="page-title">积分商城</div>
                <div class="actions">
                    <i class="fas fa-history" onclick="viewExchangeHistory()"></i>
                </div>
            </div>
        </div>
        
        <!-- 用户积分显示 -->
        <div class="user-points">
            <div class="points-label">我的积分</div>
            <div class="points-value" id="userPoints">1,000</div>
            <div class="points-note">积分可用于兑换精美商品</div>
        </div>
        
        <!-- 分类筛选 -->
        <div class="filter-section">
            <div class="filter-btn" onclick="openCategoryModal()">
                <span class="filter-btn-text" id="currentCategoryText">全部商品</span>
                <i class="fas fa-chevron-down filter-btn-icon"></i>
            </div>
        </div>
        
        <!-- 分类选择模态框 -->
        <div class="modal-overlay" id="categoryModal">
            <div class="modal-content">
                <div class="modal-header">
                    <div class="modal-title">选择分类</div>
                    <div class="modal-close" onclick="closeCategoryModal()">
                        <i class="fas fa-times"></i>
                    </div>
                </div>
                <div class="category-options">
                    <div class="category-option active" data-category="all">全部商品</div>
                    <div class="category-option" data-category="office">办公用品</div>
                    <div class="category-option" data-category="food">健康食品</div>
                    <div class="category-option" data-category="training">培训活动</div>
                    <div class="category-option" data-category="team">团建活动</div>
                    <div class="category-option" data-category="visit">参观考察</div>
                </div>
            </div>
        </div>
        
        <!-- 商品列表 -->
        <div class="products-section">
            <div class="products-grid" id="productsGrid">
                <!-- 商品将通过JavaScript动态生成 -->
            </div>
        </div>
        
        <!-- 收货信息模态框 -->
        <div class="address-modal-overlay" id="addressModal">
            <div class="address-modal-content">
                <div class="address-modal-header">
                    <div class="address-modal-title">填写收货信息</div>
                    <div class="address-modal-close" onclick="closeAddressModal()">
                        <i class="fas fa-times"></i>
                    </div>
                </div>
                <form class="address-form" id="addressForm">
                    <div class="form-group">
                        <label class="form-label">收件人姓名 *</label>
                        <input type="text" class="form-input" id="recipientName" placeholder="请输入收件人姓名" required>
                    </div>
                    <div class="form-group">
                        <label class="form-label">联系电话 *</label>
                        <input type="tel" class="form-input" id="recipientPhone" placeholder="请输入联系电话" required>
                    </div>
                    <div class="form-group">
                        <label class="form-label">收货地址 *</label>
                        <textarea class="form-textarea" id="recipientAddress" placeholder="请输入详细收货地址（省市区街道门牌号）" required></textarea>
                    </div>
                    <div class="address-form-actions">
                        <button type="button" class="btn-cancel" onclick="closeAddressModal()">取消</button>
                        <button type="submit" class="btn-confirm">确认兑换</button>
                    </div>
                </form>
            </div>
        </div>
        
        <!-- 底部导航 -->
        <div class="tabbar">
            <div class="tab-item" onclick="location.href='home.html'">
                <i class="fas fa-home"></i>
                <span>首页</span>
            </div>
            <div class="tab-item" onclick="location.href='demand-list.html'">
                <i class="fas fa-search"></i>
                <span>求购</span>
            </div>
            <div class="tab-item" onclick="location.href='publish-select.html'">
                <i class="fas fa-plus-circle"></i>
                <span>发布</span>
            </div>
            <div class="tab-item" onclick="location.href='consultation.html'">
                <i class="fas fa-comments"></i>
                <span>客服</span>
            </div>
            <div class="tab-item" onclick="location.href='profile.html'">
                <i class="fas fa-user"></i>
                <span>我的</span>
            </div>
        </div>
    </div>
    
    <script>
        // 商品数据
        const products = [
            // 办公用品
            {
                id: 1,
                name: "得力文具套装",
                points: 500,
                category: "office",
                icon: "fas fa-pen"
            },
            {
                id: 2,
                name: "小米无线鼠标",
                points: 800,
                category: "office",
                icon: "fas fa-mouse"
            },
            {
                id: 3,
                name: "罗技键盘",
                points: 1200,
                category: "office",
                icon: "fas fa-keyboard"
            },
            {
                id: 4,
                name: "苹果AirPods Pro",
                points: 2500,
                category: "office",
                icon: "fas fa-headphones"
            },
            
            // 健康食品
            {
                id: 5,
                name: "三只松鼠坚果礼盒",
                points: 300,
                category: "food",
                icon: "fas fa-cookie"
            },
            {
                id: 6,
                name: "蒙牛特仑苏牛奶",
                points: 200,
                category: "food",
                icon: "fas fa-glass-whiskey"
            },
            {
                id: 7,
                name: "燕之屋燕窝",
                points: 1500,
                category: "food",
                icon: "fas fa-heart"
            },
            {
                id: 8,
                name: "西湖龙井茶叶",
                points: 600,
                category: "food",
                icon: "fas fa-leaf"
            },
            
            // 培训活动
            {
                id: 9,
                name: "Excel办公技能培训",
                points: 1000,
                category: "training",
                icon: "fas fa-chart-bar"
            },
            {
                id: 10,
                name: "英语口语提升课程",
                points: 1500,
                category: "training",
                icon: "fas fa-language"
            },
            
            // 团建活动
            {
                id: 11,
                name: "密室逃脱体验券",
                points: 400,
                category: "team",
                icon: "fas fa-puzzle-piece"
            },
            {
                id: 12,
                name: "卡拉OK包厢券",
                points: 350,
                category: "team",
                icon: "fas fa-microphone"
            },
            
            // 参观考察
            {
                id: 13,
                name: "知名企业参观学习",
                points: 2000,
                category: "visit",
                icon: "fas fa-building"
            },
            {
                id: 14,
                name: "工业展会门票",
                points: 800,
                category: "visit",
                icon: "fas fa-ticket-alt"
            }
        ];
        
        // 当前选中的分类
        let currentCategory = 'all';
        
        // 用户积分
        const userPoints = 1000;
        
        // 初始化页面
        function initPage() {
            document.getElementById('userPoints').textContent = userPoints.toLocaleString();
            renderProducts();
            initCategoryOptions();
        }
        
        // 渲染商品列表
        function renderProducts() {
            const grid = document.getElementById('productsGrid');
            const filteredProducts = currentCategory === 'all' 
                ? products 
                : products.filter(p => p.category === currentCategory);
            
            if (filteredProducts.length === 0) {
                grid.innerHTML = `
                    <div class="empty-state" style="grid-column: 1 / -1;">
                        <i class="fas fa-gift"></i>
                        <div class="empty-title">暂无商品</div>
                        <div class="empty-desc">该分类下暂时没有可兑换的商品</div>
                    </div>
                `;
                return;
            }
            
            grid.innerHTML = filteredProducts.map(product => {
                const canExchange = userPoints >= product.points;
                
                return `
                    <div class="product-card" onclick="viewProductDetail(${product.id})">
                        <div class="product-image">
                            <i class="${product.icon}"></i>
                        </div>
                        <div class="product-name">${product.name}</div>
                        <div class="product-points">${product.points} 积分</div>
                        <button class="exchange-btn" ${!canExchange ? 'disabled' : ''} 
                                onclick="event.stopPropagation(); exchangeProduct(${product.id})">
                            ${canExchange ? '立即兑换' : '积分不足'}
                        </button>
                    </div>
                `;
            }).join('');
        }
        
        // 打开分类模态框
        function openCategoryModal() {
            document.getElementById('categoryModal').classList.add('show');
        }
        
        // 关闭分类模态框
        function closeCategoryModal() {
            document.getElementById('categoryModal').classList.remove('show');
        }
        
        // 初始化分类选项
        function initCategoryOptions() {
            const options = document.querySelectorAll('.category-option');
            options.forEach(option => {
                option.addEventListener('click', function() {
                    // 移除所有active类
                    options.forEach(o => o.classList.remove('active'));
                    // 添加active类到当前选中的选项
                    this.classList.add('active');
                    // 更新当前分类
                    currentCategory = this.dataset.category;
                    // 更新筛选按钮文本
                    document.getElementById('currentCategoryText').textContent = this.textContent;
                    // 关闭模态框
                    closeCategoryModal();
                    // 重新渲染商品
                    renderProducts();
                });
            });
        }
        
        // 查看商品详情
        function viewProductDetail(productId) {
            location.href = `prize-detail.html?id=${productId}`;
        }
        
        // 当前要兑换的商品
        let currentExchangeProduct = null;
        
        // 兑换商品
        function exchangeProduct(productId) {
            const product = products.find(p => p.id === productId);
            if (!product) return;
            
            if (userPoints < product.points) {
                alert('积分不足，无法兑换该商品');
                return;
            }
            
            // 设置当前要兑换的商品
            currentExchangeProduct = product;
            
            // 打开收货信息模态框
            openAddressModal();
        }
        
        // 打开收货信息模态框
        function openAddressModal() {
            document.getElementById('addressModal').classList.add('show');
            // 清空表单
            document.getElementById('addressForm').reset();
        }
        
        // 关闭收货信息模态框
        function closeAddressModal() {
            document.getElementById('addressModal').classList.remove('show');
            currentExchangeProduct = null;
        }
        
        // 处理收货信息表单提交
        function handleAddressSubmit(event) {
            event.preventDefault();
            
            const recipientName = document.getElementById('recipientName').value.trim();
            const recipientPhone = document.getElementById('recipientPhone').value.trim();
            const recipientAddress = document.getElementById('recipientAddress').value.trim();
            
            // 验证表单
            if (!recipientName) {
                alert('请输入收件人姓名');
                return;
            }
            
            if (!recipientPhone) {
                alert('请输入联系电话');
                return;
            }
            
            if (!recipientAddress) {
                alert('请输入收货地址');
                return;
            }
            
            // 验证手机号格式
            const phoneRegex = /^1[3-9]\d{9}$/;
            if (!phoneRegex.test(recipientPhone)) {
                alert('请输入正确的手机号码');
                return;
            }
            
            if (currentExchangeProduct) {
                // 确认兑换
                if (confirm(`确认使用 ${currentExchangeProduct.points} 积分兑换 ${currentExchangeProduct.name} 吗？\n\n收货信息：\n收件人：${recipientName}\n电话：${recipientPhone}\n地址：${recipientAddress}`)) {
                    // 这里可以发送兑换请求到服务器
                    console.log('兑换商品:', currentExchangeProduct);
                    console.log('收货信息:', {
                        name: recipientName,
                        phone: recipientPhone,
                        address: recipientAddress
                    });
                    
                    // 模拟兑换成功
                    alert('兑换成功！商品将在3-5个工作日内发货，请保持电话畅通。');
                    
                    // 关闭模态框
                    closeAddressModal();
                    
                    // 这里可以更新用户积分（实际项目中应该从服务器获取）
                    // userPoints -= currentExchangeProduct.points;
                    // document.getElementById('userPoints').textContent = userPoints.toLocaleString();
                }
            }
        }
        
        // 查看兑换记录
        function viewExchangeHistory() {
            alert('正在跳转到兑换记录页面...');
        }
        
        // 页面加载完成后初始化
        document.addEventListener('DOMContentLoaded', function() {
            initPage();
            
            // 添加收货信息表单提交事件监听器
            document.getElementById('addressForm').addEventListener('submit', handleAddressSubmit);
        });
    </script>
</body>
</html>